import React from "react";
import config from "config";
import configureStore from "stores";

const selectorData = {
  selectListCountryCode: {
    url: `${config.baseUrl}/api/custom/enumeration/system/by/type?systemCustomEnumerationType=1005`,
    label: (record) => `${record.messageKey}`,
    key: "value",
    listKey: "values",
    offlineSearchMode: true,
  },
  currency: {
    url: `${config.baseUrl}/api/currency/status/query/by/setOfBooksId`,
    label: (record) =>
      `${record.currency} ${
        configureStore.store.getState().main.language.code === "zh_cn"
          ? ` ${record.currencyName}`
          : ""
      }`,
    key: "currency",
    offlineSearchMode: true,
  },
  //通过账套id，获取账套下面的币种
  currency_for_company: {
    url: `${config.baseUrl}/api/currency/rate/list/all`,
    label: (record) =>
      `${record.currencyCode} ${
        configureStore.store.getState().main.language.code === "zh_cn"
          ? ` ${record.currencyName}`
          : ""
      }`,
    key: "currencyCode",
    offlineSearchMode: true,
    listKey: "rows",
  },
  supplier: {
    url: `${config.baseUrl}/api/suppliers`,
    label: (record) => record.name,
    key: "supplierOID",
  },
  agent: {
    label: (record) => `${record.fullName}-${record.employeeID}`,
    key: "userOID",
    offlineSearchMode: true,
    url: `${config.baseUrl}/api/bill/proxy/query/my/principals`,
  },
  // 代提报销单，获取选择了“代上级”对应的“申请人”数据源
  forBoss: {
    label: (record) => `${record.fullName}-${record.employeeID}`,
    key: "userOID",
    offlineSearchMode: true,
    url: `${config.baseUrl}/api/bill/proxy/query/my/principals?proxyType=2`,
  },
  // 代提报销单，获取选择了“代司机”对应的“申请人”数据源
  forDriver: {
    label: (record) => `${record.fullName}-${record.driverId}`,
    key: "driverId",
    offlineSearchMode: true,
    userOID: "userOID",
    url: `${config.baseUrl}/api/bill/proxy/query/my/principals?proxyType=1`,
  },
  proxyForm: {
    url: `${config.baseUrl}/api/custom/forms/my/available`,
    label: (record) => record.formName,
    key: "formOID",
    offlineSearchMode: true,
    dynamicUrl: true,
  },
  //登录员工含权限的所有表单 在审核、付款、查看页面用到 1001借款单 1002报销单
  authority_form: {
    url: `${config.baseUrl}/api/custom/forms/finance/all?showCompany=true`,
    label: (option) => (
      <section className="multiple-option">
        <div className="multiple-option-title">{option.formName}</div>
        <span className="multiple-option-content">{option.companyName}</span>
      </section>
    ),
    key: "formOID",
    labelKey: "formName",
    descriptionKey: "companyName",
    offlineSearchMode: false,
  },
  //流程监控平台所以表单
  admin_form: {
    url: `/api/admin/approvals/custom/form/v2`,
    label: (option) => (
      <section className="multiple-option">
        <div className="multiple-option-title">{option.formName}</div>
        <span className="multiple-option-content">{option.companyName}</span>
      </section>
    ),
    key: "formOID",
    labelKey: "formName",
    descriptionKey: "companyName",
    offlineSearchMode: false,
  },
  //代理设置选表单
  proxy_form_admin: {
    //参数customFormType：1001 申请单 1002 报销单 3001 借款单 4001 通用表单
    url: `${config.baseUrl}/api/custom/forms/proxy`,
    key: "formOID",
    label: (record) => record.formName,
    descriptionKey: "companyName",
  },
  proxy_form_apply: {
    //员工代理制单，选择单据，参数formType：101：申请单表单，102：报销单表单,  104：借款单表单,  103：所有 代理制单
    url: `${config.baseUrl}/api/billProxyRule/proxy/forms/search`,
    key: "formOID",
    label: (record) => record.formName,
    descriptionKey: "companyName",
  },
  proxy_form: {
    //员工代理审批 参数customFormType：1001 申请单 1002 报销单
    url: `${config.baseUrl}/api/billProxyRule/proxy/forms/audit/search`,
    key: "formOID",
    label: (record) => record.formName,
    descriptionKey: "companyName",
  },
  //表单类型，表单设置头部筛选处使用
  formTypeList: {
    url: `${config.baseUrl}/api/custom/forms/entity`,
    label: (record) => record.value,
    key: "code",
    offlineSearchMode: false,
  },
  //差补规则下差补费用类型
  subsidy_expense_type: {
    url: `${config.baseUrl}/api/travel/subsidies/rule/list`,
    label: (record) => record.expenseTypeName,
    key: "expenseTypeOID",
    offlineSearchMode: false,
  },
  //卡服务商
  cardSupplier: {
    url: `${config.baseUrl}/api/custom/enumerations/template/by/type`,
    label: (record) => record.messageKey,
    key: "value",
    offlineSearchMode: false,
  },
  //额度发放至的卡
  quotaSupplier: {
    url: `${config.baseUrl}/api/contact/bank/account/acard`,
    label: (record) =>
      record.paymentRemark
        ? `${
            record.paymentRemark === "002"
              ? messages("common-1.key1234") /*瑞贝卡*/
              : messages("common-1.key1235") /*领创A卡*/
          }(${record.bankAccountNo && record.bankAccountNo.substr(-4)})`
        : "",
    key: "contactBankAccountOID",
    offlineSearchMode: false,
    dynamicUrl: true,
  },
  quotaSupplierNoDynamic: {
    url: `${config.baseUrl}/api/contact/bank/account/acard`,
    label: (record) =>
      record.paymentRemark
        ? `${
            record.paymentRemark === "002"
              ? messages("common-1.key1234") /*瑞贝卡*/
              : messages("common-1.key1235") /*领创A卡*/
          }(${record.bankAccountNo && record.bankAccountNo.substr(-4)})`
        : "",
    key: "contactBankAccountOID",
    offlineSearchMode: false,
  },
  city: {
    url: `${config.baseUrl}/location-service/api/custom/location/search/keyword`,
    label: (record) =>
      record.path
        ? record.adName === record.countryName
          ? record.adName
          : `${record.adName}(${record.path})`
        : record.adName,
    key: "adCode",
    searchKey: "keyword",
  },
  externalExpense: {
    url: `${config.baseUrl}/api/expense/search/types`,
    label: "name",
    key: "id",
    offlineSearchMode: true,
    listKey: "expenseTypes",
  },
  expense_type_category: {
    url: `${config.baseUrl}/api/expense/types/category`,
    label: "name",
    key: "expenseTypeCategoryOID",
  },
  setOfBooksByTenant: {
    url: `${config.baseUrl}/api/setOfBooks/by/tenant`,
    label: "setOfBooksName",
    key: "id",
  },
  user: {
    url: `${config.baseUrl}/api/users/v3/search`,
    label: (record) => `${record.fullName} ${record.employeeID}`,
    key: "userOID",
    searchKey: "keyword",
  },
  //报销单费用归属人，参数expenseReportOID
  expenseOwner: {
    url: `${config.baseUrl}/api/expense/report/invoices/owner/search`,
    label: (record) => `${record.fullName} ${record.employeeId}`,
    key: "userOID",
    listKey: "rows",
  },
  //预算项目
  budget_item: {
    url: `${config.budgetUrl}/api/budget/items/query`,
    label: "itemName",
    key: "id",
    searchKey: "keyword",
  },
  //付款方式
  paymentMethod: {
    url: `${config.baseUrl}/api/expense/report/invoices/owner/search`,
    label: (record) => `${record.fullName} ${record.employeeId}`,
    key: "userOID",
    listKey: "rows",
  },
  //国家
  country: {
    url: `${
      config.baseUrl
    }/location-service/api/localization/query/country?language=${configureStore.store
      .getState()
      .main.language.code.toLowerCase()}&page=0&size=1000`,
    label: "country",
    key: "code",
    listKey: "",
    offlineSearchMode: true,
  },
  //国家
  newCountry: {
    url: `${
      config.baseUrl
    }/api/areas/country/list/continent?language=${configureStore.store
      .getState()
      .main.language.code.toLowerCase()}&page=0&size=1000`,
    label: "name",
    key: "adCode",
    listKey: "",
    offlineSearchMode: true,
  },
  //单据ID
  expense_report_id: {
    url: `/api/expense/report/loanApplication/search`,
    label: "_self",
    key: "_self",
    searchKey: "keyword",
  },
  //付款批次号
  reimbursement_batch: {
    url: "/api/reimbursement/batch/query/byBatchName",
    label: "reimbursementBatchName",
    key: "id",
    searchKey: "batchName",
  },
  business_code_expense: {
    url: "/api/expense/report/search",
    label: "_self",
    key: "_self",
    searchKey: "keyword",
  },
  business_code_borrow: {
    url: "/api/loanBill/query/business/code/by/keyword?status=",
    label: "_self",
    key: "_self",
    searchKey: "keyword",
  },
  value_list: {
    url: "/api/custom/enumerations/template/by/type",
    label: "messageKey",
    key: "code",
  },
  apy_type_list: {
    url: "/payment/api/cash/payment/method/get/payment/by/bankId/and/code",
    label: "description",
    key: "id",
    dynamicUrl: true,
  },
  expense_label: {
    label: "name",
    url: "/api/expense/labels",
    key: "id",
  },
  "entry-information": {
    url: "/ledger/api/journal/getTranDetail/by/businessCode/tenantId",
    key: "id",
    label: (item) =>
      `${item.billCode}-${
        item.paymentCurrencyCode
      } ${React.Component.prototype.filterMoney(
        item.paymentAmount,
        queryCurrencyPrecision(item.paymentCurrencyCode),
        true
      )}`,
    dynamicUrl: true,
  },
  setOfBooksByTenantDoc: {
    url: `${config.baseUrl}/api/setOfBooks/by/tenant`,
    label: (option) => (
      <section className="multiple-option">
        <div className="multiple-option-title">{option.setOfBooksName}</div>
        <span className="multiple-option-content">
          {messages("common.currency") /*币种*/}：
          {option.functionalCurrencyCode}
        </span>
      </section>
    ),
    key: "id",
  },
  city_level_org: {
    url: `${config.baseUrl}/api/levels/org`,
    key: "id",
    label: "levelName",
  },
  "invoice-labels": {
    url: `${config.baseUrl}/api/expense/labels?roleType=TENANT`,
    key: "id",
    label: "name",
  },
  user_group_book: {
    url: `/api/user/groups/search`,
    key: "id",
    label: "name",
  },
  all_department: {
    url: `${config.baseUrl}/api/department/like`,
    key: "departmentOID",
    label: "name",
  },
  "invoice-check-created": {
    url: `/config/api/config/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "invoice-check-duplicated": {
    url: `/config/api/config/factor/996642905839910913/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "invoice-check-consecutive": {
    url: `/config/api/config/factor/996642905890242562/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "invoice-check-title": {
    url: `/config/api/config/factor/996642905894436866/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "invoice-check-status": {
    url: `/config/api/config/factor/996642905844105218/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "invoice-check-result": {
    url: `/config/api/config/factor/996642905860882433/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "all_invoice_price-tax": {
    url: `/config/api/config/factor/1118154566368919558/dataList`,
    key: "id",
    label: "name",
    listKey: "rows",
  },
  "object-mapping": {
    url: `/api/open/ledger/element/value/group`,
    key: "code",
    label: "showName",
    offlineSearchMode: true,
    listKey: "data.0.ledElementValueDTOList",
  },
  vicp_titles: {
    url: "/receipt/api/receipt/vicp/titles",
    key: "key",
    label: "key",
    listKey: "rows",
    map: (list) =>
      [...new Set(list.rows)]
        .sort((item) => (item === "" ? 1 : -1))
        .map((item) => ({
          key: item || messages("common-1.key1232") /*(空值)*/,
        })),
  },
  labels: {
    url: "/api/labels",
    key: "type",
    label: "name",
    listKey: "rows",
    descriptionKey: "description",
  },
  operation: {
    offlineSearchMode: false,
    url: `/api/approval/history/get/operation/list`,
    label: "operationName",
    key: "operation",
  },
  historyFormTypeList: {
    offlineSearchMode: false,
    url: `/api/approval/history/get/form/type/name/list`,
    label: "formTypeName",
    key: "formTypeId",
  },
  invoiceBagList: {
    url: "/api/expense/reports/bag/fuzzy/query",
    label: "expenseReportBagCode",
    key: "id",
    searchKey: "expenseReportBagCode",
  },
  roleList: {
    url: "/api/security/permission/resource/tenant",
    label: "permissionName",
    key: "id",
    searchKey: "permissionName",
  },
  billNodeName: {
    url: "/api/bill/submit/nodes",
    label: "name",
    key: "key",
  },
  "expense-participants": {
    url: "/api/expense/report/participant/search",
    label: "fullName",
    key: "id",
    map: (item) => item.rows,
  },
  "expense-type": {
    url: "/api/invoice/factor/filter/invoices",
    label: "expenseTypeName",
    key: "expenseTypeId",
    map: (item) => {
      let data = [];
      item.expenseCategorys.forEach((item) => {
        item.expenseTypeDTOS &&
          item.expenseTypeDTOS[0] &&
          data.push(...item.expenseTypeDTOS);
      });
      return data;
    },
  },
  period_set: {
    url: "/api/periods/query/all",
    label: "periodName",
    key: "periodName",
    searchKey: "keyword",
    dynamicUrl: true,
  },
  accounting_period: {
    url: "/api/periods/query/open/v2",
    label: "periodName",
    key: "id",
    searchKey: "keyword",
  },
  "didi-invoice": {
    url: "/api/receipted/invoices/qualifications/query/with/authority/DIDI",
    label: "invoice_title",
    key: "invoice_title",
  },
  "didi-type": {
    url: "/api/invoice/type/DIDI",
    label: "name",
    key: "type",
  },
  receipt_payee: {
    url: "/receipt/api/receipt/vicp/payee",
    key: "key",
    label: "key",
    listKey: "rows",
    map: (list) =>
      [...new Set(list.rows)]
        .sort((item) => (item === "" ? 1 : -1))
        .map((item) => ({
          key: item || messages("common-1.key1232") /*(空值)*/,
        })),
  },
  // 获取当前租户下的所有成本中心
  cost_center_tenant_all: {
    url: `/api/cost/center/by/tenant/or/setofbooks`,
    key: "id",
    label: "name",
    searchKey: "keyword",
    dynamicUrl: true,
  },
  receipt_type: {
    url: "/api/custom/enumeration/receipt/type",
    label: "messageKey",
    key: "value",
    listKey: "rows",
    map: (list, value) => {
      if (!list.rows.some((item) => item.value === value.value)) {
        value.messageKey = messages("common-1.key1300", {
          arg1: value.messageKey,
        }) /*{arg1} （已禁用）*/;
        list.rows.push(value);
      }
      return list.rows;
    },
  },
  tax_type: {
    url: "/api/custom/enumeration/tax/rate",
    label: "taxRateKey",
    key: "taxRateValue",
    // dynamicUrl: true,
    map: (list) => list.sort((a, b) => a.taxRateValue - b.taxRateValue),
  },
  user_all: {
    url: `${config.baseUrl}/api/public/getAllUser?isLeaving=` + true,
    label: (record) => `${record.fullName} ${record.eid}`,
    key: "userOID",
    searchKey: "keyword",
  },
};

export default selectorData;
